<?php

class ArticleListing extends AbstractBox {
	protected $template = 'article/listing.tpl';
	
	protected $onPage = 10;
	protected function setup() {
		
		$articleRepository = new ArticleRepository();
		$articleRepository->setOrderBy(array('crdate' => 'desc'));
		
		$articleRepository->setLimit($this->onPage);
		$page = 1;
		if (Utils::get('page')) {
			$page = intval(Utils::get('page'));
		}
		$articleRepository->setPage($page);
		if ($GLOBALS['TSFE']->page['uid'] == 22) {
			$articles = $articleRepository->getByArticleType(array(Article::TYPE_ARTICLE, Article::TYPE_STORY));
			$count = $articleRepository->getCountByArticleType(array(Article::TYPE_ARTICLE, Article::TYPE_STORY));
		} else {
			$articles = $articleRepository->getByPidAndArticleType(intval($GLOBALS['TSFE']->page['uid']), array(Article::TYPE_ARTICLE, Article::TYPE_STORY));
			$count = $articleRepository->getCountByPidAndArticleType(intval($GLOBALS['TSFE']->page['uid']), array(Article::TYPE_ARTICLE, Article::TYPE_STORY));
		}
		
		$pages = array();
		$pageCount = ceil($count / $this->onPage);
		if ($pageCount > 1) {
			for ($i = 1; $i <= $pageCount; $i++) {
				$pages[] = $i;
			}
		}
		MySmarty::assign('pages', $pages);
		MySmarty::assign('articles', $articles);
		MySmarty::assign('actualState', Utils::get());
	}
}

?>